package HOT100;

import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * @author 是阿秋啊
 * @date 2023/03/07 19:27
 **/
public class baidu2023 {
    static class People {
        int num;
        int x;
        People(int num,int x){
            this.num = num;
            this.x = x;
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        PriorityQueue<People> queue = new PriorityQueue<>((a,b) -> {
//            System.out.println(a.num +";"+a.x);
//            System.out.println(b.num +";"+b.x);
            if (a.x == b.x) {
                return a.num - b.num;
            }
            return a.x < b.x ? -1 : 1;
        });
        for(int i = 0; i < n; i++){
            String s = sc.next();
            if(s.contains("a")){
                int num = sc.nextInt();
                int x = sc.nextInt();
                queue.offer(new People(num,x));
            }else {
                System.out.println(queue.poll().num);
            }
        }
    }
}
